package com.example.rbacmanage.service.app.impl;

import com.example.rbacmanage.entity.app.Tools;
import com.example.rbacmanage.mapper.app.ToolsMapper;
import com.example.rbacmanage.service.app.ToolsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ToolsServiceImpl implements ToolsService {
    @Autowired
    private ToolsMapper toolsMapper;
    @Override
    public void save(Tools tools) {
        tools.setCreateTime(new Date());
        toolsMapper.insert(tools);
    }

    @Override
    public void remove(Long[] ids) {
        for (Long id:ids){
            toolsMapper.del(id);
        }
    }

    @Override
    public void update(Tools tools) {
        toolsMapper.update(tools);
    }

    @Override
    public List<Tools> getAll(Tools tools) {
        return toolsMapper.list(tools);
    }

    @Override
    public PageInfo<Tools> getPage(Tools tools) {
        PageHelper.startPage(tools.getPage(),tools.getLimit());
        return new PageInfo<>(getAll(tools));
    }

    @Override
    public Tools getById(Long id) {
        return toolsMapper.queryOneById(id);
    }

    @Override
    public Integer getCount(Tools tools) {
        return toolsMapper.count(tools);
    }
}
